package com.wc.acwing.动态规划.数位DP.保险箱;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description
 * @Date Created in 2024/2/1-1:46
 * https://www.acwing.com/problem/content/5411/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int n;
    static char[] x;
    static char[] y;
    // f[i][j] 表示后面n - i + 1位置 j 为借位 的最小变换次数
    static int[][] f = new int[N][3];
    static int INF = 0x3f3f3f3f;

    /**
     * 性质1 : 每一位最多向前面借/进一位
     * 性质2 : 前面的每一步对后面都没有影响
     * f[i][j] 表示为后 n - i + 1 位进位 j 的最小步数
     * <p>
     * x[i] - y[i] + k + t == 10 * j
     * f[i][j] = f[i + 1][t] + abs(k)
     */
    public static void main(String[] args) {
        n = sc.nextInt();
        x = sc.next().toCharArray();
        y = sc.next().toCharArray();
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j < 3; j++) {
                Arrays.fill(f[i], INF);
            }
        }
        // 最后一位之的 0 位置是没有借位的,所以是 0步
        f[n][1] = 0;
        for (int i = n - 1; i >= 0; i--) {
            for (int j = 0; j < 3; j++) {
                for (int k = -9; k <= 9; k++) {
                    for (int t = 0; t < 3; t++) {
                        // k表示操作步数，t表示下一位的进位，j表示这一位是否有进位
                        if (x[i] - y[i] + k + t - 1 == 10 * (j - 1)) {
                            f[i][j] = Math.min(f[i][j], f[i + 1][t] + Math.abs(k));
                        }
                    }
                }
            }
        }
        int res = INF;
        for (int i = 0; i < 3; i++) {
            res = Math.min(f[0][i], res);
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    boolean hasNext() {
        while (st == null || !st.hasMoreElements()) {
            String s = nextLine();
            if (s == null) {
                return false;
            }
            st = new StringTokenizer(s);
        }

        return true;
    }
}
